const env: Record<string, any> = {};
env.iCrudOptions = {
  formOptions: {
    labelWidth: "100%", //form label在顶部设置
    saveRemind: false,
    dialog: {
      draggable: true,
      sticky: true,
      "reset-drag-position": true,
    },
  },
  pageOptions: {
    total: 0, // 总页码
    pageSize: 10, //页条数
  },
  searchOptions: {
    labelWidth: 80, //serar label在顶部设置
  },
  addFormOptions: {
    show: false, //新增 按钮默认隐藏
  },
  selectionRowOptions: {
    batchRemove: {
      button: {
        text: "删除",
        ghost: false,
      },
    },
  },
  componentOptions: {
    Select: {
      formatType: "tag",
      props: {
        clearable: true,
        filterable: false,
      },
    },
  },
};

//表单验证规则
env.volid = {
  //非空验证
  Must: {
    required: true,
    message: "必填项不能为空",
    trigger: "change",
  },
  //邮箱验证
  Email: {
    type: "email",
    message: "邮箱格式错误",
    trigger: "change",
  },
  //价格验证
  Price: {
    pattern: /^(\d+)((?:\.\d+)?)$/,
    message: "格式错误",
    trigger: "change",
  },
  //手机号码验证
  Mobile: {
    pattern: /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/,
    message: "手机号码格式错误",
    trigger: "change",
  },
  //正整数(只能输入数字[0-9])
  Integer: {
    pattern: /(^[0-9]\d*$)/,
    message: "正整数格式错误",
    trigger: "change",
  },
  //月份验证
  Month: {
    pattern: /^([1-9]|1[012])$/,
    message: "月份格式错误",
    trigger: "change",
  },
};

/*
 *根据数组自动生成验证规则
 *data 数据为数组
 *required 数组中对象数据可选值（true ,Must, Email, Price, Mobile , Integer）
 */
env.createRules = function (data) {
  let rules = {};
  data.map((item: any) => {
    let myRules = [];
    let type = Object.prototype.toString.call(item.required);
    if (item.type) {
      if (type === "[object Boolean]") {
        myRules.push(env.volid.Must);
      } else if (type === "[object String]") {
        const rulesKeys = item.required.split(",");
        rulesKeys.map((vv: any) => {
          const ru = env.volid[vv];
          myRules.push(ru);
        });
      }
      if (myRules.length > 0) {
        rules[item["key"]] = myRules;
      }
    }
  });
  return rules;
};
//图片地址共用域名
env.prefix = "http://qfile.nongqibang.com/";

export default env;
